package avicit.bdp.dgs.mdm.rest;

import avicit.bdp.dgs.mdm.dto.MdataMonitorDTO;
import avicit.bdp.dgs.mdm.service.MdataInterfaceService;
import avicit.bdp.dgs.mdm.service.MdataMonitorService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @金航数码科技有限责任公司
 * @作者：${tableInfo.classCreator}
 * @邮箱：${tableInfo.classMailbox}
 * @创建时间： 2023-12-06 11:02
 * @类说明：
 * @修改记录：
 */
@RestController
@Api(tags = "数据监控")
@RequestMapping("/api/bdp/dgs/mdm/monitor")
public class MdataMonitorRest {

    private static final Logger logger = LoggerFactory.getLogger(MdataMonitorRest.class);

    @Autowired
    private MdataMonitorService mdataMonitorService;
    @Autowired
    private MdataInterfaceService mdataInterfaceService;

    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "主数据ID", name = "mdataId", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "系统ID", name = "applicationId", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "操作类型", name = "operType", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(value = "推送状态", name = "pushStatus", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(value = "当前页", name = "pageNo", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize", dataType = "Int", paramType = "query")
    })
    @GetMapping("/getPageList")
    public ResponseMsg<QueryRespBean<MdataMonitorDTO>> getPageList(
            @RequestParam(required = false) String mdataId,
            @RequestParam(required = false) String applicationId,
            @RequestParam(required = false) Integer operType,
            @RequestParam(required = false) Integer pushStatus,
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        ResponseMsg<QueryRespBean<MdataMonitorDTO>> responseMsg = new ResponseMsg<>();
        QueryRespBean<MdataMonitorDTO> queryRespBean = mdataMonitorService.getPageList(mdataId, applicationId, operType, pushStatus, pageNo, pageSize);
        responseMsg.setResponseBody(queryRespBean);
        return responseMsg;
    }

    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public ResponseMsg<String> save(@RequestBody MdataMonitorDTO dto) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(mdataMonitorService.save(dto));
        return responseMsg;
    }

    @ApiOperation(value = "修改")
    @PutMapping("/update")
    public ResponseMsg<Boolean> update(@RequestBody MdataMonitorDTO dto) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        mdataMonitorService.update(dto);
        responseMsg.setResponseBody(true);
        return responseMsg;
    }

    @ApiOperation(value = "通过ID查询")
    @GetMapping("/queryById")
    public ResponseMsg<MdataMonitorDTO> queryById(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<MdataMonitorDTO> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(mdataMonitorService.queryById(id));
        return responseMsg;
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/deleteById")
    public ResponseMsg<Boolean> deleteById(@RequestParam String id) throws Exception{
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        mdataMonitorService.deleteById(id);
        return responseMsg;
    }

    @ApiOperation(value = "推送单条数据")
    @GetMapping("/pushDataById")
    public ResponseMsg<Boolean> pushDataById(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(mdataInterfaceService.pushDataById(id));
        return responseMsg;
    }

    @ApiOperation(value = "回调函数")
    @GetMapping("/callback")
    public ResponseMsg<Boolean> callback(@ApiParam(value = "logId", name = "logId") @RequestParam String logId,
                                         @ApiParam(value = "状态,1:成功 0:失败", name = "status") @RequestParam Integer status) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(mdataMonitorService.callback(logId, status));
        return responseMsg;
    }

    @ApiOperation(value = "测试接收主数据接口")
    @PostMapping("/getDataList")
    public ResponseMsg<Boolean> getDataList(@RequestBody String data, HttpServletRequest request) throws Exception {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        mdataMonitorService.getDataList(data, request);
        responseMsg.setResponseBody(true);
        return responseMsg;
    }

}
